package br.edu.ufcg.greengrid.model.job.scheduler;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.junit.Test;

import br.edu.ufcg.greengrid.model.machine.Machine;


public class FastestMachineJobSchedulerTest {

	@Test
	public void testOrderMachines() {
		
		FastestMachineJobScheduler js = new FastestMachineJobScheduler();
		List<Machine> machines = new ArrayList<Machine>(10);
		List<Machine> expected = new ArrayList<Machine>(10);

		for (int i = 10; i >= 1; i--) {
			Machine m = new Machine(String.valueOf(i));
			m.setOperationsPerSecond(i);
			machines.add(m);
			expected.add(m);
		}
		
		Collections.shuffle(machines);
		List<Machine> actual = js.orderMachines(machines);
		
		assertEquals(expected.size(), actual.size());
		Iterator<Machine> expectedIter = expected.iterator();
		Iterator<Machine> actualIter = actual.iterator();
		
		while(expectedIter.hasNext()){
			assertEquals(expectedIter.next(), actualIter.next());
		}
	}
	
}
